import org.apache.log4j.Logger;
import org.fyp.synchrona.blog.service.BloggerService;
import org.fyp.synchrona.facebook.service.FacebookService;
import org.fyp.synchrona.moodle.service.MoodleService;
import org.fyp.synchrona.twitter.service.TwitterService;
import org.fyp.synchrona.util.IUpdate;



public class ServiceManager {
	
	private static ServiceManager serviceManager;
	
	static final Logger logger = Logger.getLogger(ServiceManager.class);
	
	private ServiceManager(){
		
	}
	
	public static synchronized ServiceManager getServiceMangerObject(){
		if(serviceManager ==null){
			serviceManager=new ServiceManager();
			return serviceManager;
		}else{
			return serviceManager;
		}
	}
	
	public void updateServiceProfiles(IUpdate updateObj){
		
		if(updateObj.getServiceType().equals("www.facebook.com")){
			logger.info("[API] update from facebook");
			TwitterService tw = new TwitterService();
			BloggerService bs = new BloggerService();
			MoodleService bg = new MoodleService();
			tw.startService(updateObj);
			bs.startService(updateObj);
			bg.startService(updateObj);
		}else if(updateObj.getServiceType().equals("www.twitter.com")){
			logger.info("[API] update from twitter #############");
			FacebookService fb = new FacebookService();
			BloggerService bs = new BloggerService();
			MoodleService bg = new MoodleService();
			fb.startService(updateObj);
			bg.startService(updateObj);
			bs.startService(updateObj);
		}else if(updateObj.getServiceType().equals("www.moodle.com")){
			logger.info("[API] update from Moodle #############");
			FacebookService fb = new FacebookService();
			BloggerService bs = new BloggerService();
			TwitterService tw = new TwitterService();
			fb.startService(updateObj);
			bs.startService(updateObj);
			tw.startService(updateObj);
		}else if(updateObj.getServiceType().equals("www.blogger.com")){
			logger.info("[API] update from Blogger #############");
			TwitterService tw = new TwitterService();
			FacebookService fb = new FacebookService();
			MoodleService ms = new MoodleService();
			tw.startService(updateObj);
			ms.startService(updateObj);
			fb.startService(updateObj);
		}
	}
}
